
package com.yyfax.ph.home;

import com.yyfax.common.CLog;
import com.yyfax.infrastructure.eventbus.EventAgent;
import com.yyfax.infrastructure.mvp.Model;
import com.yyfax.infrastructure.network.NetworkHelper;
import com.yyfax.infrastructure.network.entity.BaseResultEntity;
import com.yyfax.ph.base.YJPH;
import retrofit2.http.Body;
import retrofit2.http.Header;
import retrofit2.http.POST;
import rx.Observable;

/**
 * M: 获得推荐权限
 * Created by zhangxian on 2017/6/17.<br>
 * Copyright 2017 www.yylending.com. All Rights Reserved.<br><br>
 */
public class GetRecommendPermissionModel extends Model {
	private static final String TAG = GetRecommendPermissionModel.class.getSimpleName();

	@Override
	public void onNext(Object obj) {
		CLog.i(TAG, "onNext: " + obj.toString());
		CompanyResult result = cast(obj);
		EventAgent.post(result);
	}

	@Override
	public Observable getObservable(Object params, int functionalCode) {
		Service service = (Service) NetworkHelper.createService(Service.class);
		String token = YJPH.getInstance().getPreferenceManager().getLoginToken();
		return service.bindCompany(token, (Company) params);
	}

	private interface Service {
		@POST("sys/user/recoverRcmd")
		Observable<CompanyResult> bindCompany(@Header("token") String token, @Body Company company);
	}

	public static class Company {
		String invitCode;

		public Company(String invitCode) {
			this.invitCode = invitCode;
		}
	}

	public static class CompanyResult extends BaseResultEntity<CompanyBean> {
	}

	public static class CompanyBean {
		public String code;
		public String companyName;
	}
}
